<template>
	<view v-wechat-title="this.pageTitle">
		<view class="box_1">
			<view class="item">
				<view class="tx1">
					<view class="order_ico points">
						<image :src="imgUrl + 'company_order_ico_jfcz.png'"></image>
					</view>
					<view class="name">{{ points_byname }}充值</view>
					<view class="des">
						我的{{ points_byname }}：{{ myPoints }}
					</view>
				</view>
			</view>
		</view>
		<view class="form_split_10"></view>
		<view class="box_2">
			<view class="item">选择充值套餐</view>
		</view>
		<view class="inv-top-menu-bar">
			<view class="top-menu">
				<view class="top-menu-list">
					<view class="item" :class="{
              active: active_index == index,
              time: item.recommend == 1
            }" v-for="(item, index) in dataset" :key="index" @click="changeItem(item, index)">
						<view class="tx1 substring1">{{ item.name }}</view>
						<view class="tx2">
							<text class="unit">￥</text>{{ item.expense1 }}.<text
								class="tofix">{{ item.expense2 }}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="form_split_10"></view>
		<view class="box_pay_pop">
			<u-radio-group v-model="submitData.payment">
				<!-- #ifdef MP-TOUTIAO  || MP-WEIXIN -->
				<view class="pay_item wx" @click="choosePayment('wxpay')">
					微信支付
					<u-radio class="self_check" name="wxpay" icon-size="18rpx"></u-radio>
				</view>
				<!-- #endif -->
				<!-- <view class="pay_item ali" @click="choosePayment('alipay')">
					支付宝支付
					<u-radio class="self_check" name="alipay" icon-size="18rpx"></u-radio>
				</view> -->
			</u-radio-group>
		</view>
		<view class="box_5">
			<view class="content">
				应付金额：
				<view class="price">
					<text>￥</text>
					{{ amount }}
				</view>
				<u-button class="pay_btn"
					:custom-style="{'background':'linear-gradient(to right, #f1cd91, #dab577)','color':'#92672c','padding':'20rpx 30rpx','height':'auto','line-height':'inherit'}"
					shape="circle" @click="submit">
					立即支付
				</u-button>
			</view>
		</view>
		<PaySubmit ref="paySubmit" :payment="submitData.payment" success-url="/member/order/list"></PaySubmit>
	</view>
</template>

<script>
	import PaySubmit from '@/components/service/PaySubmit'
	import http from '@/utils/http'
	import api from '@/api'
	import {
		mapState
	} from 'vuex'
	export default {
		name: 'BuyPoints',
		components: {
			PaySubmit
		},
		data() {
			return {
				imgUrl: getApp().globalData.imgUlr,
				pageTitle: '',
				active_index: 0,
				myPoints: 0,
				dataset: [],
				amount: 0.0,
				submitData: {
					service_type: 'points',
					service_id: 0,
					payment: 'wxpay'
				}
			}
		},
		created() {
			// this.pageTitle = this.$Route.meta.title
			// this.pageTitle.replace('积分', this.points_byname)
			this.fetchData()
		},
		mounted() {
			uni.setNavigationBarTitle({
				title: this.points_byname + '充值'
			})
		},
		computed: {
			...mapState({
				points_byname: state => state.config.points_byname
			})
		},
		methods: {
			choosePayment(payment) {
				this.submitData.payment = payment
			},
			fetchData() {
				console.log(123)
				http
					.get(api.points_setmeal_list, {})
					.then(res => {
						let list = res.data.data.items
						this.myPoints = res.data.data.member_points
						this.amount = list[0].expense
						this.submitData.service_id = list[0].id
						for (const iterator of list) {
							let expense_arr = iterator.expense.split('.')
							iterator.expense1 = expense_arr[0]
							iterator.expense2 = expense_arr[1]
							this.dataset.push(iterator)
						}
					})
					.catch(() => {})
			},
			changeItem(item, index) {
				this.active_index = index
				this.amount = item.expense
				this.submitData.service_id = item.id
			},
			submit() {
				this.submitData.return_url = this.$store.state.config.mobile_domain + 'member/orderlist'
				this.$refs.paySubmit.handlerSubmit(api.company_pay, this.submitData)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box_5 {
		.content {
			/deep/.pay_btn {
				position: absolute;
				right: 32rpx;
				top: 50%;
				transform: translate(0, -50%);
				padding: 22rpx 56rpx;
				font-size: 32rpx;
				height: auto;
				line-height: 1;
			}

			.price {
				text {
					font-size: 24rpx;
					font-weight: normal;
				}

				position: absolute;
				left: 176rpx;
				top: 50%;
				transform: translate(0, -50%);
				color: #ff6600;
				font-size: 36rpx;
				font-weight: bold;
			}

			position: relative;
			width: 100%;
			height: 100%;
			padding: 36rpx 34rpx;
			font-size: 30rpx;
			color: #333333;
		}

		width: 100%;
		background-color: #ffffff;
		position: fixed;
		box-shadow: 0 -2rpx 20rpx #c2c2c2;
		left: 0;
		right: 0;
		bottom: 0;
	}

	.box_pay_pop {
		.pay_item {
			&.wx {
				background-image: $wx_pay_ico;
				background-position: 6rpx center;
				background-repeat: no-repeat;
				background-size: 36rpx;
			}

			&.ali {
				background-image: $ali_pay_ico;
				background-position: 6rpx center;
				background-repeat: no-repeat;
				background-size: 40rpx;
			}

			.self_check {
				position: absolute;
				right: 30rpx;
				top: 38rpx;
			}

			position: relative;
			width: 690rpx;
			margin: 0 auto;
			padding: 32rpx 0 32rpx 60rpx;
			border-bottom: 2rpx solid #f8f8f8;
			font-size: 32rpx;
			color: #666666;
		}

		background-color: #ffffff;
		width: 100%;
		padding-bottom: 156rpx;
	}

	.inv-top-menu-bar {
		background-color: #ffffff;
		padding: 0 34rpx 30rpx;

		.top-menu {
			overflow: hidden;
			overflow-x: scroll;
			-webkit-overflow-scrolling: touch;

			&::-webkit-scrollbar {
				display: none;
			}
		}

		.top-menu-list {
			white-space: nowrap;

			.item {
				&.time::after {
					content: "推荐";
					position: absolute;
					left: -4rpx;
					top: -4rpx;
					background-color: #ff0000;
					color: #ffffff;
					font-size: 24rpx;
					border-radius: 10rpx 0 10rpx 0;
					padding: 7rpx;
				}

				.tx2 {
					font-size: 40rpx;
					font-weight: bold;
					color: #92672c;
					padding-top: 18rpx;

					.unit {
						font-weight: normal;
						font-size: 20rpx;
					}

					.tofix {
						font-size: 28rpx;
					}
				}

				.tx1 {
					font-size: 28rpx;
					font-weight: bold;
					color: #666666;
				}

				position: relative;
				width: 226rpx;
				height: 190rpx;
				text-align: center;
				padding-top: 34rpx;
				background-color: #ffffff;
				border: 4rpx solid #e2e2e2;
				border-radius: 10rpx;
				display: inline-block;
				white-space: nowrap;
				vertical-align: top;

				&.active {
					.tx1 {
						color: #92672c;
					}

					border: 4rpx solid #dab577;
					background-color: #fffcf5;
				}

				&:not(:first-child) {
					margin-left: 20rpx;
				}
			}
		}
	}

	.box_2 {
		.item {
			padding: 34rpx 0 34rpx 30rpx;
			font-size: 32rpx;
			color: #333333;
			font-weight: bold;
		}

		width: 100%;
		background-color: #ffffff;
		border-radius: 36rpx 36rpx 0 0;
		display: flex;
	}

	.box_1 {
		.item {
			.tx1 {
				.order_ico {
					&.points {
						background-position: 0;
						background-repeat: no-repeat;
						background-size: 10rpx;

						image {
							width: 100%;
							height: 100%;
						}
					}

					position: absolute;
					left: 6rpx;
					top: 30rpx;
					width: 100rpx;
					height: 100rpx;
					border-radius: 100%;
				}

				.des {
					padding: 0 20rpx 30rpx 0;
					font-size: 26rpx;
					color: #333333;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}

				.name {
					padding: 30rpx 20rpx 18rpx 0;
					font-size: 30rpx;
					color: #666666;
					font-weight: bold;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}

				position: relative;
				padding-left: 130rpx;
			}

			width: 100%;
			background-color: #ffffff;
			border-radius: 10rpx;
			padding: 0 30rpx;
			position: relative;
		}

		width: 100%;
		border-top: 2rpx solid #f3f3f3;
	}
</style>